import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QComboBox, QVBoxLayout, QWidget


class DeviceWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建设备下拉框
        self.deviceComboBox = QComboBox(self)
        self.deviceComboBox.addItems(["--请选择--",'MT-01', 'MT-02',"CA-13","DS-01"])  # 示例设备列表

        # 创建工序下拉框
        self.processComboBox = QComboBox(self)

        # 设备和工序的数据关系
        self.device_processes = {
            'MT-01': ['工序1', '工序2'],
            'MT-02': ['工序3', '工序4']
        }

        # 连接设备下拉框的currentIndexChanged信号到槽函数
        self.deviceComboBox.currentIndexChanged.connect(self.indexChange)

        # 创建布局并添加组件
        layout = QVBoxLayout()
        layout.addWidget(self.deviceComboBox)
        layout.addWidget(self.processComboBox)

        # 创建一个QWidget作为容器，并设置布局
        central_widget = QWidget(self)
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

        self.setWindowTitle('设备和工序选择')
        self.setGeometry(300, 300, 300, 200)  # x, y, width, height

    def indexChange(self):
        # 根据设备名称更新工序下拉框
        processes="1"
        self.processComboBox.clear()
        self.processComboBox.addItems(processes)

if __name__ == '__main__':
    # 创建应用程序实例
    app = QApplication(sys.argv)

    # 创建窗口实例
    window = DeviceWindow()
    window.show()

    # 运行应用程序
    sys.exit(app.exec_())
